import { watch } from 'vue';
import { useRoute } from 'vue-router';

/**
 * 页面加载或路由变化时自动执行 applyDefaultFiltersByRoute 和 handleSearch
 * @param applyDefaultFiltersByRoute 设置默认筛选逻辑
 * @param handleSearch 查询逻辑
 */
export function useAutoSearch(handleSearch: () => void) {
  const route = useRoute();

  watch(
    () => route.name,
    () => {
      handleSearch();
    },
    { immediate: true }
  );
}
